package com.ruoyi.system.controller;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TicketMovieAreaType;
import com.ruoyi.system.service.ITicketMovieAreaTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电影按区域划分ControllerN
 * 
 * @author ruoyi
 * @date 2022-01-10
 */
@Controller
@RequestMapping("/system/ticketmovieareatype")
public class TicketMovieAreaTypeController extends BaseController
{
    private String prefix = "system/ticketmovieareatype";

    @Autowired
    private ITicketMovieAreaTypeService ticketMovieAreaTypeService;

    @RequiresPermissions("system:ticketmovieareatype:view")
    @GetMapping()
    public String ticketmovieareatype()
    {
        return prefix + "/ticketmovieareatype";
    }

    /**
     * 查询电影按区域划分列表
     */
    @RequiresPermissions("system:ticketmovieareatype:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TicketMovieAreaType ticketMovieAreaType)
    {
        startPage();
        List<TicketMovieAreaType> list = ticketMovieAreaTypeService.selectTicketMovieAreaTypeList(ticketMovieAreaType);
        return getDataTable(list);
    }

    /**
     * 导出电影按区域划分列表
     */
    @RequiresPermissions("system:ticketmovieareatype:export")
    @Log(title = "电影按区域划分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TicketMovieAreaType ticketMovieAreaType)
    {
        List<TicketMovieAreaType> list = ticketMovieAreaTypeService.selectTicketMovieAreaTypeList(ticketMovieAreaType);
        ExcelUtil<TicketMovieAreaType> util = new ExcelUtil<TicketMovieAreaType>(TicketMovieAreaType.class);
        return util.exportExcel(list, "电影按区域划分数据");
    }

    /**
     * 新增电影按区域划分
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电影按区域划分
     */
    @RequiresPermissions("system:ticketmovieareatype:add")
    @Log(title = "电影按区域划分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TicketMovieAreaType ticketMovieAreaType)
    {
        return toAjax(ticketMovieAreaTypeService.insertTicketMovieAreaType(ticketMovieAreaType));
    }

    /**
     * 修改电影按区域划分
     */
    @RequiresPermissions("system:ticketmovieareatype:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TicketMovieAreaType ticketMovieAreaType = ticketMovieAreaTypeService.selectTicketMovieAreaTypeById(id);
        mmap.put("ticketMovieAreaType", ticketMovieAreaType);
        return prefix + "/edit";
    }

    /**
     * 修改保存电影按区域划分
     */
    @RequiresPermissions("system:ticketmovieareatype:edit")
    @Log(title = "电影按区域划分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TicketMovieAreaType ticketMovieAreaType)
    {
        return toAjax(ticketMovieAreaTypeService.updateTicketMovieAreaType(ticketMovieAreaType));
    }

    /**
     * 删除电影按区域划分
     */
    @RequiresPermissions("system:ticketmovieareatype:remove")
    @Log(title = "电影按区域划分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ticketMovieAreaTypeService.deleteTicketMovieAreaTypeByIds(ids));
    }

    //获取电影区域类型列表
    @GetMapping("/getAreaTypeList")
    @ResponseBody
    public AjaxResult getAreaTypeList(TicketMovieAreaType ticketMovieYear)
    {
        List<TicketMovieAreaType> list = this.ticketMovieAreaTypeService.selectTicketMovieAreaTypeList(ticketMovieYear);
        AjaxResult result = new AjaxResult();
        JSONArray array = new JSONArray();
        for(TicketMovieAreaType item : list)
        {
            array.add(item.getAreaName());
        }
        result.put("array", array);
        return result;
    }
}
